/*
 * @Author: your name
 * @Date: 2021-05-23 19:38:09
 * @LastEditTime: 2021-05-28 15:32:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/store/storeModal/index.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-23 19:37:51
 * @LastEditTime: 2021-05-23 19:37:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/store/storeModal.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-23 19:02:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { Modal } from 'antd';
import HeaderForm from '@/components/form';

import React, { useEffect } from 'react';
import { SEX } from '@/enum';
import { FormInstance } from 'antd';
import { add_store, edit_store, get_chains } from '@/services/pages';
import useObj from '@/use/useObj';
import { globalModel } from '../../globalModel';
import { observer } from 'mobx-react';
import { IForm } from '../../../components/form/interface';
import { toJS } from 'mobx';
import { edit_vip } from '../../../services/pages';
interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const EditModal = (props: IProps) => {
  console.log(globalModel.chainList, 'globalModel==');

  const List: IForm[] = [
    {
      key: 'vip_name',
      type: IFormTypeEnum.Input,
      label: '会员卡名称',
      rules: [{ required: true }],
    },
    {
      key: 'vip_desc',
      type: IFormTypeEnum.Input,
      label: '会员卡描述',
    },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    console.log(form, 'form===');
    if (props.row?.vip_id) {
      await edit_vip({ ...values, vip_id: props.row.vip_id });
    }
    props.close();
    props.refresh();
  };

  return (
    <Modal
      maskClosable={false}
      visible={props.visible}
      title={props.row?.vip_id ? '编辑会员卡' : '添加会员卡'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={110}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={props.row}
      />
    </Modal>
  );
};
export default observer(EditModal);
